/-app
/-boot
/-imports
/-storage ...
/-storage/attached ...
/-storage/attached/api
LocalStorageStorage.ts
WebSQLStorage.ts
/-tests
/-typings
stringUtils.ts
teapo.html
275
        if (result.rows) {
276
          for (var i = 0; i < result.rows.length; i++) {
277
            var row = result.rows.item(i);
278
            properties[row.name] = row.value;
279
          }
280
        }
281
 
282
        return properties;
283
      }
284
    }
285
 
286
    export class UpdateStorage implements attached.UpdateStorage {
287
 
288
      private _cachedUpdateStatementsByFile: { [name: string]: string; } = {};
289
      private _unhandledClosure = (e: SQLError) => this.unhandledSQLError(e);
290
      private _unhandledTransClosure = (t: SQLTransaction, e: SQLError) => this.unhandledSQLError(e);
291
 
292
      constructor(
293
        private _db: Database,
294
        existingFiles: string[]) {
295
        existingFiles.forEach(file=> this._createUpdateStatement(file));
296
      }
297
 
298
      update(file: string, property: string, value: string) {
299
        var updateSQL = this._cachedUpdateStatementsByFile[file];
300
        if (typeof updateSQL === 'string') {
301
          this._db.transaction(
302
            transaction=> transaction.executeSql(
303
              updateSQL,
304
              [property, value],
305
              (transaction, result) => { },
306
              this._unhandledTransClosure),
307
            this._unhandledClosure);
308
        }
309
        else {
310
          this._createTable(
311
            mangleDatabaseObjectName(file),
312
            transaction => { });
313
        }
314
      }
315
 
316
      remove(file: string) {
317
        this._db.transaction(
318
          transaction =>
319
            transaction.executeSql(
320
              'DROP TABLE "' + mangleDatabaseObjectName(file) + '"',
321
              [],
322
              (transaction, result) => { },
323
              this._unhandledTransClosure),
324
          this._unhandledClosure);
325
      }
326
 
327
      unhandledSQLError(sqlError: SQLError) {
328
        if (typeof console !== 'undefined' && console && console.error)
329
          console.error(sqlError);
330
      }
331
 
332
      private _createUpdateStatement(file: string) {
333
        return this._cachedUpdateStatementsByFile[file] =
334
          'INSERT OR REPLACE INTO "' +
335
          mangleDatabaseObjectName(file) +
336
          '" VALUES (?,?)';
337
      }
338
 
339
      private _createTable(tableName: string, callback: (transaction: SQLTransaction) => void) {
340
 
341
        this._db.transaction(
342
          transaction=>
343
            transaction.executeSql(
344
              'CREATE TABLE "' + tableName + '" (name PRIMARY KEY, value)',
345
              [],
346
              (transaction, result) => callback(transaction),
347
              this._unhandledTransClosure),
348
          this._unhandledClosure);
349
 
350
      }
351
 
352
      private _updateEditedCore(transaction: SQLTransaction) {
353